package user

import (
	"context"

	"go-zero_try/mall/order/api/internal/svc"
	"go-zero_try/mall/order/api/internal/types"
	"go-zero_try/mall/order/rpc/pb/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserModifyLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserModifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserModifyLogic {
	return &UserModifyLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserModifyLogic) UserModify(req *types.RegisterAndModifyReq) (resp *types.RegsiterAndModifyReps, err error) {
	userResp, err := l.svcCtx.UserClient.Modify(l.ctx, &pb.ModAndRgsReq{
		UID:      req.UID,
		Name:     req.Name,
		Password: req.Pwd,
		Age:      req.Age,
	})

	if err != nil {
		return nil, err
	}

	return &types.RegsiterAndModifyReps{
		Msg:  userResp.Msg,
		UID:  userResp.UID,
		Name: userResp.Name,
		Age:  userResp.Age,
	}, nil
}
